/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.live.multishop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.common.model.LiveRoomBack;
import com.yami.shop.live.common.service.LiveRoomBackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lhd
 * @date 2020-08-12 10:04:53
 */
@RestController
@RequestMapping("/live/liveRoomBack")
@Api(tags = "商家端直播间回放接口")
public class LiveRoomBackController {

    @Autowired
    private LiveRoomBackService liveRoomBackService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查找直播间回放信息")
    public ServerResponseEntity<IPage<LiveRoomBack>> getLiveRoomBackPage(PageParam<LiveRoomBack> page, LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.page(page, new LambdaQueryWrapper<LiveRoomBack>()));
    }

    @GetMapping("/info/{backId}")
    @ApiOperation(value = "通过id查询直播间回放信息")
    @ApiImplicitParam(name = "backId", value = "直播间回放id", required = true, dataType = "Long")
    public ServerResponseEntity<LiveRoomBack> getById(@PathVariable("backId") Long backId) {
        return ServerResponseEntity.success(liveRoomBackService.getById(backId));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:save')")
    @ApiOperation(value = "新增直播间回放信息")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.save(liveRoomBack));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:update')")
    @ApiOperation(value = "修改直播间回放信息")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.updateById(liveRoomBack));
    }

    @DeleteMapping("/{backId}")
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:delete')")
    @ApiOperation(value = "通过id删除直播间回放信息")
    @ApiImplicitParam(name = "backId", value = "直播间回放id", required = true, dataType = "Long")
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long backId) {
        return ServerResponseEntity.success(liveRoomBackService.removeById(backId));
    }
}
